<?php
/* 	These code was generated using phpCIGen v 0.1.b (1/08/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id
	
	+ Module  		: m_job View
	+ Description	: For record view
	+ Filename 		: v_m_job.php
 	+ Author  		: 
 	+ Created on 24/Jul/2012 11:02:41
	
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}
		
		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */		
var m_job_DataStore;
var m_job_ColumnModel;
var m_jobListEditorGrid;
var m_job_saveForm;
var m_job_saveWindow;
var m_job_searchForm;
var m_job_searchWindow;
var m_job_SelectedRow;
//for detail data
var m_jobdet_DataStore;
var m_jobdetListEditorGrid;
var m_jobdet_ColumnModel;
var m_jobdet_proxy;
var m_jobdet_reader;
var editor_m_jobdet;

//declare konstant
var INFO_REQUIRED="Wajib diisi";
var post2db = '';
var msg = '';
var pageS=15;

/* declare variable here for Field*/
var job_idField;
var job_nameField;
var job_kodeField;
var job_activeYesRadioField;
var job_activeNoRadioField;
var job_divField;
var job_idSearchField;
var job_nameSearchField;
var job_activeSearchField;
var job_created_dateSearchField;
var job_created_bySearchField;
var job_divSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */

  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  
  	/* Function for add and edit data form, open window form */
	function m_job_save(){
	
		if(is_m_job_form_valid()){	
			var job_id_field_pk=null; 
			var job_kode_field=null; 
			var job_name_field=null; 
			var job_div_field=null;
			var job_active_field='Y';

			job_id_field_pk=get_pk_id();
			if(job_kodeField.getValue()!== null){job_kode_field = job_kodeField.getValue();} 
			if(job_nameField.getValue()!== null){job_name_field = job_nameField.getValue();} 
			if(job_divField.getValue()!== null){job_div_field = job_divField.getValue();}
			if(job_activeNoRadioField.getValue()){job_active_field = 'T';}

			//console.log(m_jobdetListEditorGrid.getStore().data.items[0].data.jobdet_name);
			
			//push data detail
			var jobdet_id_field = [];
			var jobdet_name_field = [];
			var jobdet_store = m_jobdetListEditorGrid.getStore();
			for(var i=0; i<jobdet_store.getCount(); i++){
				if(jobdet_store.getAt(i).data.jobdet_name!==undefined
						&& jobdet_store.getAt(i).data.jobdet_name!==''){
					jobdet_id_field.push(jobdet_store.getAt(i).data.jobdet_id);
					jobdet_name_field.push(jobdet_store.getAt(i).data.jobdet_name);
				}
			}
			var encoded_array_jobdet_id = Ext.encode(jobdet_id_field);
			var encoded_array_jobdet_name = Ext.encode(jobdet_name_field);
			
			Ext.Ajax.request({  
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_m_job&m=get_action',
				params: {
					job_id: job_id_field_pk, 
					job_kode: job_kode_field, 
					job_name: job_name_field, 
					job_active: job_active_field, 
					job_div: job_div_field,
					//data detail
					jobdet_id: encoded_array_jobdet_id,
					jobdet_name: encoded_array_jobdet_name,
					task: post2db
				}, 
				success: function(response){             
					var result=eval(response.responseText);
					if(result!==0){
							Ext.MessageBox.alert(post2db+' OK','Data berhasil disimpan.');
							m_job_DataStore.reload();
							m_job_saveWindow.hide();
					}else{
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: 'Data gagal Disimpan.',
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
						}        
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: 'Koneksi database server gagal, hubungi Administrator',
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});	
				}                      
			});
			
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Data input belum sempurna',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
 	/* End of Function */
  
  	/* Function for get PK field */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return m_jobListEditorGrid.getSelectionModel().getSelected().get('job_id');
		return 0;
	}
	/* End of Function  */
	
	/* Reset form before loading */
	function m_job_reset_form(){
		job_idField.reset();
		job_idField.setValue(null);
		job_kodeField.reset();
		job_kodeField.setValue(null);
		job_nameField.reset();
		job_nameField.setValue(null);
		job_activeYesRadioField.setValue(true);
		job_activeNoRadioField.setValue(false);
		job_divField.reset();
		job_divField.setValue(null);
		
		//remove all data detail
		m_jobdet_DataStore.removeAll();
	}
 	/* End of Function */
  
	/* setValue to EDIT */
	function m_job_set_form(){
		job_idField.setValue(m_jobListEditorGrid.getSelectionModel().getSelected().get('job_id'));
		job_kodeField.setValue(m_jobListEditorGrid.getSelectionModel().getSelected().get('job_kode'));
		job_nameField.setValue(m_jobListEditorGrid.getSelectionModel().getSelected().get('job_name'));
		// job_divField.setValue(m_jobListEditorGrid.getSelectionModel().getSelected().get('div_name'));
		console.log(m_jobListEditorGrid.getSelectionModel().getSelected().get('m_div_id'));
		job_divField.setValue(m_jobListEditorGrid.getSelectionModel().getSelected().get('m_div_id'));
		if(m_jobListEditorGrid.getSelectionModel().getSelected().get('job_active') == 'Y'){
			job_activeYesRadioField.setValue(true);
		}else{
			job_activeNoRadioField.setValue(true);
		}
		m_jobdet_DataStore.setBaseParam('master_id',m_jobListEditorGrid.getSelectionModel().getSelected().get('job_id'));
		m_jobdet_DataStore.setBaseParam('start', 0);
		m_jobdet_DataStore.setBaseParam('limit', pageS);
		m_jobdet_DataStore.load();
	}
	/* End setValue to EDIT*/
  
	/* Function for Check if the form is valid */
	function is_m_job_form_valid(){
		return ( job_kodeField.isValid() && job_nameField.isValid() && job_divField.isValid() );
	}
  	/* End of Function */
  
  	/* Function for Displaying  create Window Form */
	function display_form_window(){
		if(!m_job_saveWindow.isVisible()){
			m_job_reset_form();
			post2db='CREATE';
			msg='created';
			m_job_saveWindow.show();
		} else {
			m_job_saveWindow.toFront();
		}
	}
  	/* End of Function */
 
  	/* Function for Delete Confirm */
	function m_job_confirm_delete(){
		// only one m_job is selected here
		if(m_jobListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', m_job_delete);
		} else if(m_jobListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', m_job_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */
  
	/* Function for Update Confirm */
	function m_job_confirm_update(){
		/* only one record is selected here */
		if(m_jobListEditorGrid.selModel.getCount() == 1) {
			m_job_set_form();
			post2db='UPDATE';
			msg='updated';
			m_job_saveWindow.show();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk diupdate',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */
  
  	/* Function for Delete Record */
	function m_job_delete(btn){
		if(btn=='yes'){
			var selections = m_jobListEditorGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< m_jobListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.job_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({ 
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_m_job&m=get_action', 
				params: { task: "DELETE", ids:  encoded_array }, 
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:  // Success : simply reload
							m_job_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Data gagal dihapus',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: 'Koneksi database server gagal, hubungi Administrator',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});	
				}
			});
		}  
	}
  	/* End of Function */
  
	/* START DATA */
	m_job_DataStore = new Ext.data.Store({
		id: 'm_job_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_m_job&m=get_action', 
			method: 'POST'
		}),
		baseParams:{task: "LIST"}, // parameter yang di $_POST ke Controller
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'job_id'
		},[
		/* dataIndex => insert intom_job_ColumnModel, Mapping => for initiate table column */ 
			{name: 'job_id', type: 'int', mapping: 'job_id'}, 
			{name: 'job_kode', type: 'string', mapping: 'job_kode'}, 
			{name: 'job_name', type: 'string', mapping: 'job_name'}, 
			{name: 'job_active', type: 'string', mapping: 'job_active'}, 
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'm_div_id', type: 'string', mapping: 'm_div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'}
		]),
		sortInfo:{field: 'job_id', direction: "DESC"}
	});

	divDataStore = new Ext.data.Store({
		id: 'divDataStore',
		autoLoad : true,
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_div', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'div_id'
		},[
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'},
			{name: 'div_active', type: 'string', mapping: 'div_active'}
		]),
		sortInfo:{field: 'div_name', direction: "ASC"}
	});
	/* END DATA */
    
  	/* Function for Identify of Window Column Model */
	m_job_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Kode Material / Pekerjaan',
			dataIndex: 'job_kode',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextField({
				maxLength: 45			})
		}, {
			header: 'Nama Material / Pekerjaan',
			dataIndex: 'job_name',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextField({
				maxLength: 45			})
		},  
		{
			header: 'Kategori Biaya',
			dataIndex: 'div_name',
			width: 150,
			sortable: false
		},{
			header: 'Aktif',
			dataIndex: 'job_active',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextField({
				allowBlank: false,
				maxLength: 1			})
		}	]);
	
	m_job_ColumnModel.defaultSortable= true;
	/* End of Function */
    
	/* Declare DataStore and  show datagrid list */
	m_jobListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'm_jobListEditorGrid',
		el: 'fp_m_job',
		title: 'Data Material / Pekerjaan',
		autoHeight: true,
		store: m_job_DataStore, // DataStore
		cm: m_job_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 700,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: m_job_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Tambah',
			tooltip: 'Tambah data baru',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: display_form_window
		}, '-',{
			text: 'Ubah',
			tooltip: 'Ubah data',
			iconCls:'icon-update',
			handler: m_job_confirm_update   // Confirm before updating
		}, '-',{
			text: 'Hapus',
			tooltip: 'Hapus data',
			iconCls:'icon-delete',
			handler: m_job_confirm_delete   // Confirm before deleting
		}/* , '-', {
			text: 'Search',
			tooltip: 'Advanced Search',
			iconCls:'icon-search',
			handler: display_form_search_window 
		} */, '-', 
		new Ext.app.SearchField({
			store: m_job_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						m_job_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
					Ext.get(this.id).set({qtitle: 'Pencarian Sederhana'});
				}
			},
			width: 120
		}),'-',{
			text: 'Refresh',
			tooltip: 'Refresh data',
			handler: m_job_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: 'Export Excel',
			tooltip: 'Export ke bentuk excel',
			iconCls:'icon-xls',
			handler: m_job_export_excel
		}, '-',{
			text: 'Cetak',
			tooltip: 'Cetak data',
			iconCls:'icon-print',
			handler: m_job_print  
		}
		]
	});
	m_jobListEditorGrid.render();
	/* End of DataStore */
    
  	
	m_job_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
	
	/* Identify  job_id Field */
	job_idField= new Ext.form.NumberField({
		id: 'job_idField',
		allowNegatife : false,
		blankText: '0',
		allowBlank: false,
		allowDecimals: false,
		hidden: true,
		readOnly: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  job_name Field */
	job_kodeField= new Ext.form.TextField({
		id: 'job_kodeField',
		fieldLabel: 'Kode Material / Pekerjaan <font color=red>*</font>',
		maxLength: 45,
		anchor: '95%'
	});
	job_nameField= new Ext.form.TextField({
		id: 'job_nameField',
		fieldLabel: 'Nama Material / Pekerjaan <font color=red>*</font>',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  job_div Field */
	// job_divField= new Ext.form.ComboBox({
		// id: 'job_divField',
		// fieldLabel: 'Kategori Biaya <font color=red>*</font>',
		// store: divDataStore,
		// mode: 'remote',
		// displayField:'div_name',
		// valueField: 'div_id',
        // editable: true,
		// anchor: '95%',
		// pageSize: 15,
		// triggerAction: 'all'
	// });
	job_divField = new Ext.ux.form.SuperBoxSelect({
	id: 'job_divField',
		fieldLabel: 'Kategori Biaya <font color=red>*</font>',
		store: divDataStore,
		mode: 'remote',
		displayField:'div_name',
		valueField: 'div_id',
        editable: true,
		anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	job_activeYesRadioField=new Ext.form.Radio({
		fieldLabel : 'Aktif',
		name : 'job_active',
		boxLabel: 'Ya',
		inputValue: 'Y'
	});
	
	job_activeNoRadioField=new Ext.form.Radio({
		fieldLabel : '',
		name : 'job_active',
		boxLabel: 'Tidak',
		inputValue: 'T'
	});
	
  	/*Fieldset Master*/
	m_job_masterGroup = new Ext.form.FieldSet({
		title: 'Master ',
		autoHeight: true,
		collapsible: true,
		layout:'form',
		items:[{
				layout: 'column',
				border: false,
				items:[{
						columnWidth:0.5,
				    	layout: 'form',
						border:false,
						items: [job_idField, job_kodeField,job_nameField,
							{
								columnWidth:1,
								layout: 'column',
								border: false,
								items:[
									{
										columnWidth:0.5,
										layout: 'form',
										border: false,
										items:[job_activeYesRadioField]
									},
									{
										columnWidth:0.3,
										layout: 'form',
										border: false,
										labelWidth: 10,
										items:[job_activeNoRadioField]
									}]
							}
						]
					},{
						columnWidth:0.5,
						layout: 'form',
						border:false,
						items: [job_divField]
					}
				]
			}, new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })
		]
	});
	
		
	/*Detail Declaration */
	// Function for json reader of detail
	var m_jobdet_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id: ''
	},[
	/* dataIndex => insert intoperawatan_ColumnModel, Mapping => for initiate table column */ 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'}, 
			{name: 'jobdet_active', type: 'string', mapping: 'jobdet_active'}, 
			{name: 'jobdet_created_date', type: 'date', dateFormat: 'm-d-Y H:i:s', mapping: 'jobdet_created_date'}, 
			{name: 'jobdet_created_by', type: 'string', mapping: 'jobdet_created_by'}, 
			{name: 'jobdet_updated_date', type: 'date', dateFormat: 'm-d-Y H:i:s', mapping: 'jobdet_updated_date'}, 
			{name: 'jobdet_updated_by', type: 'string', mapping: 'jobdet_updated_by'}, 
			{name: 'jobdet_updated_count', type: 'int', mapping: 'jobdet_updated_count'}, 
			{name: 'm_job_job_id', type: 'int', mapping: 'm_job_job_id'}, 
			{name: 'm_job_job_div', type: 'int', mapping: 'm_job_job_div'} 
	]);
	//eof
	
	/* Function for Retrieve DataStore of detail*/
	m_jobdet_DataStore = new Ext.data.Store({
		id: 'm_jobdet_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_m_job&m=detail_m_jobdet_list', 
			method: 'POST'
		}),
		reader: m_jobdet_reader,
		sortInfo:{field: 'jobdet_id', direction: "ASC"}
	});
	/* End of Function */
	
	//function for editor of detail
	var editor_m_jobdet= new Ext.ux.grid.RowEditor({
        saveText: 'Update'
    });
	//eof
	
	//declaration of detail coloumn model
	m_jobdet_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Jenis, Merk, dan Ukuran Material / Pekerjaan',
			dataIndex: 'jobdet_name',
			editor: new Ext.form.TextField({
				maxLength: 200			
			})
		}]
	);
	m_jobdet_ColumnModel.defaultSortable= true;
	//eof

	//declaration of detail list editor grid
	m_jobdetListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'm_jobdetListEditorGrid',
		el: 'fp_m_jobdet',
		title: 'Data Detail Material / Pekerjaan',
		height: 250,
		width: 690,
		autoScroll: true,
		store: m_jobdet_DataStore, // DataStore
		colModel: m_jobdet_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_m_jobdet],
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: m_jobdet_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: m_jobdet_add
		}, '-',{
			text: 'Delete',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_jobdet_confirm_delete
		}
		]
	});
	//eof
	
	
	//function of detail add
	function m_jobdet_add(){
		var edit_m_jobdet= new m_jobdetListEditorGrid.store.recordType({
			jobdet_id	:0,		
			jobdet_name	:''
		});
		editor_m_jobdet.stopEditing();
		m_jobdet_DataStore.insert(0, edit_m_jobdet);
		//m_jobdetListEditorGrid.getView().refresh();
		m_jobdetListEditorGrid.getSelectionModel().selectRow(0);
		editor_m_jobdet.startEditing(0);
	}
	
	//function for refresh detail
	function refresh_m_jobdet(){
		//m_jobdet_DataStore.commitChanges();
		//m_jobdetListEditorGrid.getView().refresh();
	}
	//eof
	
	/* Function for Delete Confirm of detail */
	function m_jobdet_confirm_delete(){
		// only one record is selected here
		if(m_jobdetListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', m_jobdet_delete);
		} else if(m_jobdetListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', m_jobdet_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	//eof
	
	//function for Delete of detail
	function m_jobdet_delete(btn){
		if(btn=='yes'){
			var s = m_jobdetListEditorGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				m_jobdet_DataStore.remove(r);
			}
		}  
	}
	//eof
	
	//event on update of detail data store
	//m_jobdet_DataStore.on('update', refresh_m_jobdet);
	
	/* Function for retrieve create Window Panel*/ 
	m_job_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 700,        
		items: [m_job_masterGroup,m_jobdetListEditorGrid]
		,
		buttons: [{
				text: 'Save and Close',
				handler: m_job_save
			}
			,{
				text: 'Cancel',
				handler: function(){
					m_job_saveWindow.hide();
				}
			}
		]
	});
	

	/* Function for retrieve create Window Form */
	m_job_saveWindow= new Ext.Window({
		id: 'm_job_saveWindow',
		title: post2db+' Material / Pekerjaan',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		x:0,
		y:0,
		plain:true,
		layout: 'fit',
		modal: true,
		renderTo: 'elwindow_m_job_save',
		items: m_job_saveForm
	});
	/* End Window */
	
	/* Function for action list search */
	function m_job_list_search(){
		// render according to a SQL date format.
		var job_id_search=null;
		var job_name_search=null;
		var job_active_search=null;
		var job_created_date_search_date="";
		var job_created_by_search=null;
		var job_div_search=null;

		if(job_idSearchField.getValue()!==null){job_id_search=job_idSearchField.getValue();}
		if(job_nameSearchField.getValue()!==null){job_name_search=job_nameSearchField.getValue();}
		if(job_activeSearchField.getValue()!==null){job_active_search=job_activeSearchField.getValue();}
		if(job_created_dateSearchField.getValue()!==""){job_created_date_search_date=job_created_dateSearchField.getValue().format('m-d-Y');}
		if(job_created_bySearchField.getValue()!==null){job_created_by_search=job_created_bySearchField.getValue();}
		if(job_divSearchField.getValue()!==null){job_div_search=job_divSearchField.getValue();}
		// change the store parameters
		m_job_DataStore.baseParams = {
			task: 'SEARCH',
			//variable here
			job_id	:	job_id_search, 
			job_name	:	job_name_search, 
			job_active	:	job_active_search, 
			job_created_date	:	job_created_date_search_date, 
			job_created_by	:	job_created_by_search, 
			job_div	:	job_div_search 
		};
		// Cause the datastore to do another query : 
		m_job_DataStore.reload({params: {start: 0, limit: pageS}});
	}
		
	/* Function for reset search result */
	function m_job_reset_search(){
		// reset the store parameters
		m_job_DataStore.baseParams = { task: 'LIST' };
		// Cause the datastore to do another query : 
		m_job_DataStore.reload({params: {start: 0, limit: pageS}});
		m_job_searchWindow.close();
	};
	/* End of Fuction */
	
	/* Field for search */
	/* Identify  job_id Search Field */
	job_idSearchField= new Ext.form.NumberField({
		id: 'job_idSearchField',
		fieldLabel: 'Job Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	
	});
	/* Identify  job_name Search Field */
	job_nameSearchField= new Ext.form.TextField({
		id: 'job_nameSearchField',
		fieldLabel: 'Job Name',
		maxLength: 45,
		anchor: '95%'
	
	});
	/* Identify  job_active Search Field */
	job_activeSearchField= new Ext.form.TextField({
		id: 'job_activeSearchField',
		fieldLabel: 'Job Active',
		maxLength: 1,
		anchor: '95%'
	
	});
	/* Identify  job_created_date Search Field */
	job_created_dateSearchField= new Ext.form.DateField({
		id: 'job_created_dateSearchField',
		fieldLabel: 'Job Created Date',
		format : 'm-d-Y',
	
	});
	/* Identify  job_created_by Search Field */
	job_created_bySearchField= new Ext.form.TextField({
		id: 'job_created_bySearchField',
		fieldLabel: 'Job Created By',
		maxLength: 45,
		anchor: '95%'
	
	});
	/* Identify  job_div Search Field */
	job_divSearchField= new Ext.form.NumberField({
		id: 'job_divSearchField',
		fieldLabel: 'M Div Div Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	
	});
    
	/* Function for retrieve search Form Panel */
	m_job_searchForm = new Ext.FormPanel({
		labelAlign: 'top',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 300,        
		items: [{
			layout:'column',
			border:false,
			items:[
			{
				columnWidth:1,
				layout: 'form',
				border:false,
				items: [job_nameSearchField, job_activeSearchField, job_created_dateSearchField, job_created_bySearchField, job_divSearchField] 
			}
			]
		}]
		,
		buttons: [{
				text: 'Search',
				handler: m_job_list_search
			},{
				text: 'Close',
				handler: function(){
					m_job_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */ 
	 
	/* Function for retrieve search Window Form, used for andvaced search */
	m_job_searchWindow = new Ext.Window({
		title: 'm_job Search',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_m_job_search',
		items: m_job_searchForm
	});
    /* End of Function */ 
	 
  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!m_job_searchWindow.isVisible()){
			m_job_searchWindow.show();
		} else {
			m_job_searchWindow.toFront();
		}
	}
  	/* End Function */
	
	/* Function for print List Grid */
	function m_job_print(){
		var searchquery = "";
		var job_name_print=null;
		var job_active_print=null;
		var job_created_date_print_date="";
		var job_created_by_print=null;
		var job_div_print=null;
		var win;              
		// check if we do have some search data...
		if(m_job_DataStore.baseParams.query!==null){searchquery = m_job_DataStore.baseParams.query;}
		if(m_job_DataStore.baseParams.job_name!==null){job_name_print = m_job_DataStore.baseParams.job_name;}
		if(m_job_DataStore.baseParams.job_active!==null){job_active_print = m_job_DataStore.baseParams.job_active;}
		if(m_job_DataStore.baseParams.job_created_date!==""){job_created_date_print_date = m_job_DataStore.baseParams.job_created_date;}
		if(m_job_DataStore.baseParams.job_created_by!==null){job_created_by_print = m_job_DataStore.baseParams.job_created_by;}
		if(m_job_DataStore.baseParams.job_div!==null){job_div_print = m_job_DataStore.baseParams.job_div;}

		Ext.Ajax.request({   
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_job&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,                    		// if we are doing a quicksearch, use this
			//if we are doing advanced search, use this
			job_name : job_name_print,
			job_active : job_active_print,
		  	job_created_date : job_created_date_print_date, 
			job_created_by : job_created_by_print,
			job_div : job_div_print,
		  	currentlisting: m_job_DataStore.baseParams.task // this tells us if we are searching or not
		}, 
		success: function(response){              
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.open('./print/m_job_printlist.html','m_joblist','height=400,width=600,resizable=1,scrollbars=1, menubar=1');
				win.print();
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: 'Data gagal dicetak',
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}  
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Koneksi database server gagal, hubungi Administrator',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});		
		} 	                     
		});
	}
	/* Enf Function */
	
	/* Function for print Export to Excel Grid */
	function m_job_export_excel(){
		var searchquery = "";
		var job_name_2excel=null;
		var job_active_2excel=null;
		var job_created_date_2excel_date="";
		var job_created_by_2excel=null;
		var job_div_2excel=null;
		// check if we do have some search data...
		if(m_job_DataStore.baseParams.query!==null){searchquery = m_job_DataStore.baseParams.query;}
		if(m_job_DataStore.baseParams.job_name!==null){job_name_2excel = m_job_DataStore.baseParams.job_name;}
		if(m_job_DataStore.baseParams.job_active!==null){job_active_2excel = m_job_DataStore.baseParams.job_active;}
		if(m_job_DataStore.baseParams.job_created_date!==""){job_created_date_2excel_date = m_job_DataStore.baseParams.job_created_date;}
		if(m_job_DataStore.baseParams.job_created_by!==null){job_created_by_2excel = m_job_DataStore.baseParams.job_created_by;}
		if(m_job_DataStore.baseParams.job_div!==null){job_div_2excel = m_job_DataStore.baseParams.job_div;}

		Ext.Ajax.request({   
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_m_job&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,                    		// if we are doing a quicksearch, use this
			//if we are doing advanced search, use this
			job_name : job_name_2excel,
			job_active : job_active_2excel,
		  	job_created_date : job_created_date_2excel_date, 
			job_created_by : job_created_by_2excel,
			job_div : job_div_2excel,
		  	currentlisting: m_job_DataStore.baseParams.task // this tells us if we are searching or not
		},
		success: function(response){              
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.open('./print/m_job_printlist.xls','m_joblist','height=400,width=600,resizable=1,scrollbars=1, menubar=1');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: 'Data gagal diexport ke Excel',
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}  
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Koneksi database server gagal, hubungi Administrator',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});    
		} 	                     
		});
	}
	/*End of Function */
	
});
</script>
<body>
<div>
	<div class="col">
        <div id="fp_m_job"></div>
        <div id="fp_m_jobdet"></div>
		<div id="elwindow_m_job_save"></div>
        <div id="elwindow_m_job_search"></div>
    </div>
</div>
</body>
</html>